/*
* Copyright (c) 2011 adVolition
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* Except as contained in this notice, the name(s) of the above
* copyright holders shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
 */

package NeuralNetwork;
import java.lang.Math.*;
import com.thoughtworks.xstream.annotations.*;

/**
 * This is a collection of traits that affect the rate at which mutations occur
 * whenever the robot is cloned.
 */
public class Mutability {
    @XStreamAlias("addNode") protected Trait _addNode;
    @XStreamAlias("deleteNode") protected Trait _deleteNode;
    @XStreamAlias("mutateNode") protected Trait _mutateNode;
    @XStreamAlias("cloneEdge") protected Trait _cloneEdge;
    @XStreamAlias("deleteEdge") protected Trait _deleteEdge;
    @XStreamAlias("mutateEdge") protected Trait _mutateEdge;
    @XStreamAlias("targetParent") protected Trait _linkToParent;
    @XStreamAlias("mutateThreshold") protected Trait _mutateThreshold;
    @XStreamAlias("mutateFlux") protected Trait _mutateFlux;
    @XStreamAlias("addBundle") protected Trait _addBundle;
    @XStreamAlias("cloneBundle") protected Trait _cloneBundle;
    @XStreamAlias("deleteBundle") protected Trait _deleteBundle;

    public Mutability() {
        readResolve();
    }
    
    public Object readResolve() {
        if (_addNode == null) _addNode = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_deleteNode == null) _deleteNode = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_mutateNode == null) _mutateNode = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_cloneEdge == null) _cloneEdge = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_deleteEdge == null) _deleteEdge = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_mutateEdge == null) _mutateEdge = new Trait(0.4, 0.0, 0.4, 0.9);
        if (_linkToParent == null) _linkToParent = new Trait(0.9, 0.0, 1.0, 0.9);
        if (_mutateThreshold == null) _mutateThreshold = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_mutateFlux == null) _mutateFlux = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_addBundle == null) _addBundle = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_cloneBundle == null) _cloneBundle = new Trait(0.1, 0.0, 0.2, 0.9);
        if (_deleteBundle == null) _deleteBundle = new Trait(0.1, 0.0, 0.2, 0.9);
        return this;
    }

    public Mutability getClone() {
        Mutability fidelity = new Mutability();
        fidelity.setAddNode(_addNode.getClone());
        fidelity.setDeletNode(_deleteNode.getClone());
        fidelity.setMutateNode(_mutateNode.getClone());
        fidelity.setCloneEdge(_cloneEdge.getClone());
        fidelity.setDeleteEdge(_deleteEdge.getClone());
        fidelity.setMutateEdge(_mutateEdge.getClone());
        fidelity.setLinkToParent(_linkToParent.getClone());
        fidelity.setMutateThreshold(_mutateThreshold.getClone());
        fidelity.setMutateFlux(_mutateFlux.getClone());
        fidelity.setAddBundle(_addBundle.getClone());
        fidelity.setCloneBundle(_cloneBundle.getClone());
        fidelity.setDeleteBundle(_deleteBundle.getClone());

        return fidelity;
    }

    public Double getAddNode() {
        return _addNode.getProbability();
    }

    public void setAddNode(Trait trait) {
        _addNode = trait;
    }

    public Double getDeleteNode() {
        return _deleteNode.getProbability();
    }

    public void setDeletNode(Trait trait) {
        _deleteNode = trait;
    }

    public Double getMutateNode() {
        return _mutateNode.getProbability();
    }

    public void setMutateNode(Trait trait) {
        _mutateNode = trait;
    }

    public Double getCloneEdge() {
        return _cloneEdge.getProbability();
    }

    public void setCloneEdge(Trait trait) {
        _cloneEdge = trait;
    }

    public Double getDeleteEdge() {
        return _deleteEdge.getProbability();
    }

    public void setDeleteEdge(Trait trait) {
        _deleteEdge = trait;
    }

    public Double getMutateEdge() {
        return _mutateEdge.getProbability();
    }

    public void setMutateEdge(Trait trait) {
        _mutateEdge = trait;
    }

    public Double getLinkToParent() {
        return _linkToParent.getProbability();
    }

    public void setLinkToParent(Trait trait) {
        _linkToParent = trait;
    }

    public Double getMutateThreshold() {
        return _mutateThreshold.getProbability();
    }

    public void setMutateThreshold(Trait trait) {
        _mutateThreshold = trait;
    }

    public Double getMutateFlux() {
        return _mutateFlux.getProbability();
    }

    public void setMutateFlux(Trait trait) {
        _mutateFlux = trait;
    }

    public Double getAddBundle() {
        return _addBundle.getProbability();
    }

    public void setAddBundle(Trait trait) {
        _addBundle = trait;
    }

    public Double getDeleteBundle() {
        return _deleteBundle.getProbability();
    }

    public void setDeleteBundle(Trait trait) {
        _deleteBundle = trait;
    }

    public Double getCloneBundle() {
        return _cloneBundle.getProbability();
    }

    public void setCloneBundle(Trait trait) {
        _cloneBundle = trait;
    }
}
